package com.wanghang89.gmail.http.crawler;

import java.lang.reflect.Method;
import java.util.Map;

import org.jsoup.nodes.Document;

public abstract class AbstractCrawler {
	
	private Class clazz;
	
	public AbstractCrawler()
	{
		clazz = this.getClass();
		
		try {
			System.out.println(clazz.getSimpleName());
			Method method = clazz.getMethod("crawl");
			if (method!=null) {
				System.out.println(method.getName());
			}
			System.out.println(method.isAnnotationPresent(Crawl.class));
			Crawl crawl = method.getAnnotation(Crawl.class);
			System.out.println(crawl.method());
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
		
	}
	
	/**
	 * @details	获取入口url
	 * @return String
	 */
	protected abstract String getEntranceUrl();
	
	/**
	 * @details	构建请求url
	 * @param parameters 参数列表
	 * @return String
	 */
	protected abstract String buildRequestUrl(Object... parameters);
	
	/**
	 * @details 获取页面编码
	 * @return String
	 */
	protected abstract String getPageEncoding();

	/**
	 * @details	获取参数编码
	 * @return String
	 */
	protected abstract String getParameterEncoding();
	
	/**
	 * @details	从文档中获取请求状态信息
	 * @param doc html文档
	 * @return Map<String,String>
	 */
	protected abstract Map<String,String> getRequestStatus(Document doc);
	
}
